<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>1_非受控组件</title>
</head>
<body>
  <!-- 准备一个容器 -->
  <div id="test"></div>

  <!-- 导入react包 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>

  <script type="text/babel">
    // 创建组件
    class Login extends React.Component{

      /*
        非受控组件: 直接从标签中取值的方式
      */

      // 
      username = React.createRef()
      password = React.createRef()

      // 提交表单
      fromDataSubmit = ()=>{
        event.preventDefault()  // 取消点击按钮后的跳转动作
        const {username, password} = this
        alert(`用户名: ${this.username.current.value}, 密码: ${this.password.current.value}`)
      }

      inputData = ()=>{
        const {username} = this
      }

      inputData2 = ()=>{
        const {password} = this
      }

      render(){
        return(
          <div>
            <form onSubmit={this.fromDataSubmit}>
              UserName: <input  ref={this.username} type="text" name="username" /><br/>
              PassWord: <input ref={this.password} type="password"  name="password"/><br/>
              <button>Login</button>
            </form>
          </div>
        )
      }
    }

    // 渲染组件到页面
    ReactDOM.render(<Login/>, document.getElementById('test'))
  </script>

</body>

</html>